package biz.obake.team.touchprotector.f;

import android.os.Handler;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import biz.obake.team.touchprotector.R;
import biz.obake.team.touchprotector.f.l;

public final class b implements l {
    /* access modifiers changed from: private */

    /* renamed from: b  reason: collision with root package name */
    public final long f1591b = 1000;
    /* access modifiers changed from: private */

    /* renamed from: c  reason: collision with root package name */
    public CardView f1592c;

    /* renamed from: d  reason: collision with root package name */
    private TextView f1593d;
    private final int e;
    private final int f;
    /* access modifiers changed from: private */
    public float g;
    private float h;
    /* access modifiers changed from: private */
    public int i;
    /* access modifiers changed from: private */
    public final Handler j;
    /* access modifiers changed from: private */
    public final a k;
    /* access modifiers changed from: private */
    public final C0071b l;
    /* access modifiers changed from: private */
    public final c m;
    /* access modifiers changed from: private */
    public final d n;
    /* access modifiers changed from: private */
    public final e o;
    /* access modifiers changed from: private */
    public f p;
    private final k q;

    private final class a extends f {
        public a() {
            super();
        }

        public boolean c(MotionEvent motionEvent) {
            d.h.b.c.c(motionEvent, "e");
            if (motionEvent.getActionMasked() != 0) {
                return false;
            }
            b.this.w(motionEvent);
            d(b.this.l);
            return false;
        }
    }

    /* renamed from: biz.obake.team.touchprotector.f.b$b  reason: collision with other inner class name */
    private final class C0071b extends f {

        /* renamed from: biz.obake.team.touchprotector.f.b$b$a */
        static final class a implements Runnable {

            /* renamed from: b  reason: collision with root package name */
            final /* synthetic */ C0071b f1596b;

            a(C0071b bVar) {
                this.f1596b = bVar;
            }

            public final void run() {
                C0071b bVar = this.f1596b;
                bVar.d(b.this.m);
            }
        }

        public C0071b() {
            super();
        }

        public void a() {
            b.this.j.postDelayed(new a(this), b.this.f1591b);
        }

        public void b() {
            b.this.j.removeCallbacksAndMessages((Object) null);
        }

        public boolean c(MotionEvent motionEvent) {
            f fVar;
            d.h.b.c.c(motionEvent, "e");
            int actionMasked = motionEvent.getActionMasked();
            if (actionMasked == 1) {
                fVar = b.this.k;
            } else if (actionMasked == 2 && !b.this.t(motionEvent)) {
                return false;
            } else {
                fVar = b.this.o;
            }
            d(fVar);
            return false;
        }
    }

    private final class c extends f {
        public c() {
            super();
        }

        public void a() {
            CardView h = b.this.f1592c;
            if (h != null) {
                h.setVisibility(0);
            }
            biz.obake.team.touchprotector.c.x();
        }

        public void b() {
            CardView h = b.this.f1592c;
            if (h != null) {
                h.setVisibility(8);
            }
        }

        public boolean c(MotionEvent motionEvent) {
            f fVar;
            d.h.b.c.c(motionEvent, "e");
            int actionMasked = motionEvent.getActionMasked();
            if (actionMasked == 1) {
                fVar = b.this.k;
            } else if (actionMasked != 2) {
                fVar = b.this.o;
            } else if (!b.this.t(motionEvent)) {
                return false;
            } else {
                fVar = b.this.n;
            }
            d(fVar);
            return false;
        }
    }

    private final class d extends f {
        public d() {
            super();
        }

        public void a() {
            CardView h = b.this.f1592c;
            if (h != null) {
                h.setVisibility(0);
            }
        }

        public void b() {
            CardView h = b.this.f1592c;
            if (h != null) {
                h.setVisibility(8);
            }
        }

        public boolean c(MotionEvent motionEvent) {
            f fVar;
            d.h.b.c.c(motionEvent, "e");
            int actionMasked = motionEvent.getActionMasked();
            if (actionMasked == 1) {
                fVar = b.this.k;
            } else if (actionMasked != 2) {
                fVar = b.this.o;
            } else {
                int i = 100;
                int f = ((b.this.i < 0 || b.this.i > 100) ? 50 : b.this.i) + ((int) (((double) (((float) 50) * biz.obake.team.touchprotector.c.t(motionEvent.getX() - b.this.g))) / 125.98425196850394d));
                if (f >= 110) {
                    i = -1;
                } else if (f < 0) {
                    i = 0;
                } else if (f <= 100) {
                    i = f;
                }
                biz.obake.team.touchprotector.g.a.q("backlight", i);
                b.this.x();
                return false;
            }
            d(fVar);
            return false;
        }
    }

    private final class e extends f {
        public e() {
            super();
        }

        public boolean c(MotionEvent motionEvent) {
            d.h.b.c.c(motionEvent, "e");
            if (motionEvent.getActionMasked() != 1) {
                return false;
            }
            d(b.this.k);
            return false;
        }
    }

    private class f {
        public f() {
        }

        public void a() {
        }

        public void b() {
        }

        public abstract boolean c(MotionEvent motionEvent);

        public void d(f fVar) {
            d.h.b.c.c(fVar, "nextState");
            if (!d.h.b.c.a(b.this.p, fVar)) {
                b.this.p.b();
                b.this.p = fVar;
                b.this.p.a();
            }
        }
    }

    public b(k kVar) {
        d.h.b.c.c(kVar, "mPV");
        this.q = kVar;
        ViewConfiguration viewConfiguration = ViewConfiguration.get(biz.obake.team.android.a.a());
        d.h.b.c.b(viewConfiguration, "ViewConfiguration.get(Ba…pplication.getInstance())");
        int scaledPagingTouchSlop = viewConfiguration.getScaledPagingTouchSlop();
        this.e = scaledPagingTouchSlop;
        this.f = scaledPagingTouchSlop * scaledPagingTouchSlop;
        this.j = new Handler();
        u();
        this.k = new a();
        this.l = new C0071b();
        this.m = new c();
        this.n = new d();
        this.o = new e();
        this.p = this.k;
    }

    /* access modifiers changed from: private */
    public final boolean t(MotionEvent motionEvent) {
        float x = motionEvent.getX() - this.g;
        float y = motionEvent.getY() - this.h;
        return (x * x) + (y * y) > ((float) this.f);
    }

    private final void u() {
        View findViewById = this.q.findViewById(R.id.pv_backlight_gesture_white);
        d.h.b.c.b(findViewById, "mPV.findViewById<CardVie…_backlight_gesture_white)");
        ((CardView) findViewById).setVisibility(8);
        View findViewById2 = this.q.findViewById(R.id.pv_backlight_gesture_dark);
        d.h.b.c.b(findViewById2, "mPV.findViewById<CardVie…v_backlight_gesture_dark)");
        ((CardView) findViewById2).setVisibility(8);
    }

    /* JADX WARNING: type inference failed for: r0v3, types: [android.view.View] */
    /* JADX WARNING: Multi-variable type inference failed */
    /* JADX WARNING: Removed duplicated region for block: B:16:0x0040  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    private final void v() {
        /*
            r4 = this;
            java.lang.String r0 = "backlight_gesture_panel"
            java.lang.String r0 = biz.obake.team.touchprotector.g.a.l(r0)
            r1 = 0
            if (r0 != 0) goto L_0x000a
            goto L_0x003b
        L_0x000a:
            int r2 = r0.hashCode()
            r3 = 3075958(0x2eef76, float:4.310335E-39)
            if (r2 == r3) goto L_0x0027
            r3 = 113101865(0x6bdcc29, float:7.1393885E-35)
            if (r2 == r3) goto L_0x0019
            goto L_0x003b
        L_0x0019:
            java.lang.String r2 = "white"
            boolean r0 = r0.equals(r2)
            if (r0 == 0) goto L_0x003b
            biz.obake.team.touchprotector.f.k r0 = r4.q
            r2 = 2131296526(0x7f09010e, float:1.8210971E38)
            goto L_0x0034
        L_0x0027:
            java.lang.String r2 = "dark"
            boolean r0 = r0.equals(r2)
            if (r0 == 0) goto L_0x003b
            biz.obake.team.touchprotector.f.k r0 = r4.q
            r2 = 2131296525(0x7f09010d, float:1.821097E38)
        L_0x0034:
            android.view.View r0 = r0.findViewById(r2)
            androidx.cardview.widget.CardView r0 = (androidx.cardview.widget.CardView) r0
            goto L_0x003c
        L_0x003b:
            r0 = r1
        L_0x003c:
            r4.f1592c = r0
            if (r0 == 0) goto L_0x004a
            r1 = 2131296327(0x7f090047, float:1.8210568E38)
            android.view.View r0 = r0.findViewById(r1)
            r1 = r0
            android.widget.TextView r1 = (android.widget.TextView) r1
        L_0x004a:
            r4.f1593d = r1
            r4.x()
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: biz.obake.team.touchprotector.f.b.v():void");
    }

    /* access modifiers changed from: private */
    public final void w(MotionEvent motionEvent) {
        this.g = motionEvent.getX();
        this.h = motionEvent.getY();
        this.i = biz.obake.team.touchprotector.g.a.j("backlight");
    }

    /* access modifiers changed from: private */
    public final void x() {
        String str;
        if (this.f1593d != null) {
            String w = biz.obake.team.touchprotector.c.w(R.string.pv_backlight);
            if (w != null) {
                int j2 = biz.obake.team.touchprotector.g.a.j("backlight");
                if (j2 < 0 || j2 > 100) {
                    str = biz.obake.team.touchprotector.c.w(R.string.pv_backlignt_no_control);
                    if (str == null) {
                        throw new d.e("null cannot be cast to non-null type kotlin.String");
                    }
                } else {
                    StringBuilder sb = new StringBuilder();
                    sb.append(j2);
                    sb.append('%');
                    str = sb.toString();
                }
                String d2 = m.d(w, "{0}", str, false, 4, (Object) null);
                TextView textView = this.f1593d;
                if (textView != null) {
                    textView.setText(d2);
                    return;
                }
                return;
            }
            throw new d.e("null cannot be cast to non-null type kotlin.String");
        }
    }

    public void a() {
        this.p.d(this.k);
    }

    public boolean b(MotionEvent motionEvent) {
        d.h.b.c.c(motionEvent, "event");
        if (biz.obake.team.touchprotector.donation.a.p() && biz.obake.team.touchprotector.g.a.g("backlight_gesture") && !this.q.g()) {
            return this.p.c(motionEvent);
        }
        this.p.d(this.k);
        return false;
    }

    public void c() {
        l.a.d(this);
    }

    public void d() {
        v();
        this.p.d(this.k);
    }
}
